﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using Exhibition.Dao;
using Exhibition.IService;

namespace Exhibition.Service.Service
{
    public class OperatingDataService : IOperatingDataService
    {

        OperatingDataDao dao = new OperatingDataDao();
        /// <summary>
        /// 通用删除
        /// </summary>
        /// <param name="id">主键ID</param>
        /// <param name="tableName">表名</param>
        /// <returns></returns>
        public bool DeleteData(int id, string tableName)
        {
            return dao.DeleteData(id,tableName);  
        }

        /// <summary>
        /// 通用查询单条数据返回实体
        /// </summary>
        /// <typeparam name="T">实体类型</typeparam>
        /// <param name="id">ID</param>
        /// <param name="tableName">数据库表名</param>
        /// <returns>返回数据</returns>
        public T SelectData<T>(int id, string tableName)
        {
            return dao.SelectData<T>(id, tableName);
        }

        public int ExecuteNonQuery(string strSQL)
        {
            return dao.ExecuteNonQuery(strSQL);
        }

        public DataTable GetCommonData(string tableName)
        {
            return dao.GetCommonData(tableName);
        }

        public DataTable GetCommonData(string tableName, int rows, int page, string orderString, string isdel, out int total)
        {
            return dao.GetCommonData(tableName,rows,page,orderString,isdel,out total);
        }


        public DataTable GetCommonData(string tableName, int rows, int page, string orderString, out int total)
        {
            return dao.GetCommonData(tableName,rows,page,orderString,out total);
        }

        //public DataTable GetProcData(string procName, int rows, int page, string strWhere, out int total)
        //{
        //    DbCommand dbCommand = db.GetStoredProcCommand(procName);
        //    total = 0;
        //    db.AddInParameter(dbCommand, "PageSize", DbType.Int32, rows);
        //    db.AddInParameter(dbCommand, "PageIndex", DbType.Int32, (page + 1));
        //    db.AddInParameter(dbCommand, "strWhere", DbType.String, strWhere);
        //    db.AddInParameter(dbCommand, "rowcount", DbType.Int32, 4);
        //    DataSet ds = db.ExecuteDataSet(dbCommand);
        //    //获取总数暂未获取，To be continue...
        //    return ds.Tables[0];
        //}

        /// <summary>
        /// 获取一条数据，如果存在多条则只返回第一条数据
        /// </summary>
        /// <param name="tableName">表名</param>
        /// <param name="where">过滤条件</param>
        /// <returns></returns>
        public DataTable GetSingleData(string tableName, string where)
        {
            return dao.GetSingleData(tableName,where);
        }

        public int DataIsDistanct(string tableName, int id, string codeName, string codeValue, string isDelete)
        {
            return dao.DataIsDistanct(tableName,id,codeName,codeValue,isDelete);

        }



        public bool PhyDeleteData(int id, string tableName)
        {
            return dao.PhyDeleteData(id,tableName);
        }
    }
}
